package com.lanan.springboot.controller.front;

import com.lanan.springboot.model.Comment;
import com.lanan.springboot.model.Topic;
import com.lanan.springboot.service.ICommentService;
import com.lanan.springboot.service.ITopicService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;

/**
 * @desc CommentController
 * @author lanan
 * @date 2022-04-30 21:54:41
 **/
@Controller
@RequestMapping("/comment")
public class CommentController extends BaseController {

    @Resource
    private ICommentService commentService;
    @Resource
    private ITopicService topicService;

    /**
     * @desc 编辑评论
     * @author lanan
     * @date 2022-03-18 15:32:43
     * @param id
     * @param model
     * @return java.lang.String
     **/
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable Integer id, Model model) {
        Comment comment = commentService.selectById(id);
        Topic topic = topicService.selectById(comment.getTopicId());
        model.addAttribute("comment", comment);
        model.addAttribute("topic", topic);
        return render("comment/edit");
    }
}
